/*
 * copyright (c) 2013 Blaise-Florentin Collin
 *
 * This file is part of astroDCAM.
 *
 * AstroAviBrowser is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License v3
 * as published by the Free Software Foundation
 *
 * AstroAviBrowser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * v3 along with AstroAviBrowser; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA
 */

///
/// \file frame.hpp
/// \brief Frames definitions
///

#ifndef _FRAME_HPP_
#define _FRAME_HPP_

// std c includes
#include <stdint.h>

// std c++ includes
#include <string>

using namespace std;

///
/// \class frame
/// \brief Store a full video frame
///
class frame {
   public :

      // frame color types
      static const int MONO;
      static const int BAYER_RGGB;
      static const int BAYER_GRBG;
      static const int BAYER_GBRG;
      static const int BAYER_BGGR;
      static const int BAYER_CYYM;
      static const int BAYER_YCMY;
      static const int BAYER_YMCY;
      static const int BAYER_MYYC;
      static const int RGB;
      static const int BGR;

      // frame errors
      static const int NO_ERROR;
      static const int NO_MEM;
      static const int INVALID_ARGS;

      // constructors
      frame();
      frame(int w,int h,int c,int d, string o, string cam, string t, int64_t date, int64_t dateUTC);
      frame(const frame &f);

      // destructor
      ~frame();

      // copy operator
      frame& operator=(const frame &f);

      // setters
      int setWidth(int w);
      int setHeight(int h);
      int setColor(int c);
      int setDepth(int d);
      void setObserver(string o) { observer=o; }
      void setCamera(string cam) { camera=cam; }
      void setTelescope(string t) { telescope=t; }
      void setDate(int64_t date) { frameDate=date; }
      void setDateUTC(int64_t dateUTC) { frameDateUTC=dateUTC; }

      // getters
      int getWidth() { return(width); }
      int getHeight() { return(height); }
      int getColor() { return(color); }
      int getDepth() { return(depth); }
      string getObserver() { return(observer); }
      string getCamera() { return(camera); }
      string getTelescope() { return(telescope); }
      int64_t getDate() { return(frameDate); }
      int64_t getDateUTC() { return(frameDateUTC); }

   private :

      // frame properties
      int width; ///< frame width
      int height; ///< frame height
      int color; ///< frame color type
      int depth; ///< frame depth per pixel/plan, 1 or 2 bytes

      // metas
      string observer;
      string camera;
      string telescope;
      int64_t frameDate;
      int64_t frameDateUTC;

      // mem storage
      unsigned char* mono_plan; ///< monochrome pixel array
      unsigned char* red_plan; ///< color red pixel array
      unsigned char* green_plan; ///< color green pixel array
      unsigned char* blue_plan; ///< color blue pixel array

      // release all memory
      void releaseMem(); ///< release all frame pointers
      int allocateMem(int w, int h, int c, int d); ///< allocate all frame pointers, rollback if fails
};

#endif
